const express=require('express')
const second=express.Router()
const axios=require('axios')

//分页查询小分类
second.get('/Classse/queryForSmallByPage',(req,res)=>{
    let {pageNow,pageSize}=req.query
    axios({
        method:'get',
        url:'/Admin/Classfy/queryForSmallByPage',
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
            token:(req.session.token?req.session.token:'')
        },
        params:{
            pageNow:pageNow||1,
            pageSize:pageSize||6,
        }
    }).then(value=>{
        res.status(200).json({
            key:value.data
        })
    }).catch(err=>{
        res.status(200).json({
            error:err
        })
    })
})

//增加小分类
second.post('/Classse/add',(req,res)=>{
    let {classfyName,fatherId,fatherName}=req.query
    axios({
        method:'post',
        url:'/Admin/Classfy/add',
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
            token:(req.session.token?req.session.token:'')
        },
        params:{
            classfyName:classfyName,
            fatherId:fatherId,
            fatherName:fatherName
        }
    }).then(value=>{
        res.status(200).json({
            key:value.data
        })
    }).catch(err=>{
        res.status(200).json({
            error:err
        })
    })
})

//修改小分类
second.get('/Classse/update',(req,res)=>{
    let {classfyName,fatherId,fatherName,id}=req.query
    console.log(id);
    axios({
        method:'put',
        url:'/Admin/Classfy/update',
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
            token:(req.session.token?req.session.token:'')
        },
        params:{
            id:id,
            classfyName:classfyName,
            fatherId:fatherId,
            fatherName:fatherName
        }
    }).then(value=>{
        res.status(200).json({
            key:value.data
        })
    }).catch(err=>{
        res.status(200).json({
            error:err
        })
    })
})

module.exports=second